/*
 * @Author: liuqiang
 * @Date: 2021-03-02 14:21:04
 * @Last Modified by: liuqiang
 * @Last Modified time: 2021-03-02 15:12:55
 */

const { findBill, deleteBill } = require("../models/bill");

const billCtl = {
  // 查询账单
  find: async (ctx) => {
    const params = ctx.query;
    let res = await findBill(params);
    if (res.err) {
      ctx.body = {
        err: -999,
        msg: "查询失败！",
        data: [],
      };
      return;
    }
    ctx.body = {
      err: 0,
      msg: "查询成功",
      data: res,
    };
  },
  deleteBill: async (ctx) => {
    const { id } = ctx.request.body;
    if (!id) {
      ctx.body = {
        err: -1,
        msg: "id不能为空",
      };
      return;
    }
    let res = await deleteBill(id);
    ctx.body = {
      err: 0,
      msg: "删除成功",
      data: res,
    };
  },
};

module.exports = billCtl;
